package member2;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Input extends JPanel {
	ArrayList<Data> list;
	private JTextField inIrum;
	private JTextField inAddr;
	private JTextField inPhon;
	private JTextField inEmai;
	private JTextField inAge;
	private JLabel lblNewLabel;
	private JLabel lblAddress;
	private JLabel lblPhone;
	private JLabel lblEmail;
	private JLabel lblAge;
	private JLabel lblOut;
	private JButton btnInput;
	private JLabel lblNewLabel_1;

	public Input(ArrayList list) {
		this.list=list; // call by reference 이기 때문에, 값을 바꾸는 것이 아니라 모두 같은 주소 값을 참조하도록 하는 것이다.
		setBackground(Color.PINK);
		setLayout(null);
		add(getInIrum());
		add(getInAddr());
		add(getInPhon());
		add(getInEmai());
		add(getInAge());
		add(getLblNewLabel());
		add(getLblAddress());
		add(getLblPhone());
		add(getLblEmail());
		add(getLblAge());
		add(getLblOut());
		add(getBtnInput());
		add(getLblNewLabel_1());

	}
	
		
	private JTextField getInIrum() {
		if (inIrum == null) {
			inIrum = new JTextField();
			inIrum.setBounds(81, 55, 220, 21);
			inIrum.setColumns(10);
		}
		return inIrum;
	}
	private JTextField getInAddr() {
		if (inAddr == null) {
			inAddr = new JTextField();
			inAddr.setColumns(10);
			inAddr.setBounds(81, 86, 220, 21);
		}
		return inAddr;
	}
	private JTextField getInPhon() {
		if (inPhon == null) {
			inPhon = new JTextField();
			inPhon.setColumns(10);
			inPhon.setBounds(81, 117, 220, 21);
		}
		return inPhon;
	}
	private JTextField getInEmai() {
		if (inEmai == null) {
			inEmai = new JTextField();
			inEmai.setColumns(10);
			inEmai.setBounds(81, 148, 220, 21);
		}
		return inEmai;
	}
	private JTextField getInAge() {
		if (inAge == null) {
			inAge = new JTextField();
			inAge.setColumns(10);
			inAge.setBounds(81, 179, 220, 21);
		}
		return inAge;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Name");
			lblNewLabel.setBounds(12, 58, 57, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblAddress() {
		if (lblAddress == null) {
			lblAddress = new JLabel("Address");
			lblAddress.setBounds(12, 89, 57, 15);
		}
		return lblAddress;
	}
	private JLabel getLblPhone() {
		if (lblPhone == null) {
			lblPhone = new JLabel("Phone");
			lblPhone.setBounds(12, 120, 57, 15);
		}
		return lblPhone;
	}
	private JLabel getLblEmail() {
		if (lblEmail == null) {
			lblEmail = new JLabel("Email");
			lblEmail.setBounds(12, 151, 57, 15);
		}
		return lblEmail;
	}
	private JLabel getLblAge() {
		if (lblAge == null) {
			lblAge = new JLabel("Age");
			lblAge.setBounds(12, 182, 57, 15);
		}
		return lblAge;
	}
	private JLabel getLblOut() {
		if (lblOut == null) {
			lblOut = new JLabel("Please fill every forms");
			lblOut.setBounds(81, 210, 220, 15);
		}
		return lblOut;
	}
	private JButton getBtnInput() {
		if (btnInput == null) {
			btnInput = new JButton("Input");
			btnInput.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					/*ch[index].checkIn = new Date();
					SimpleDateFormat sb = new SimpleDateFormat("yy-MM-dd hh:mm");				
					String str2 = sb.format(ch[index].checkIn);*/
					
					
					String n = inIrum.getText();
					String ad = inAddr.getText();
					String p = inPhon.getText();
					String e = inEmai.getText();
					int ag = Integer.parseInt(inAge.getText());
					Date now = new Date();
					
					
					Data a = new Data( n, ad, p, e, ag, now);
					list.add(a);
					inIrum.setText("");
					inAddr.setText("");
					inPhon.setText("");
					inEmai.setText("");
					inAge.setText("");
				}
			});
			btnInput.setBounds(81, 235, 97, 23);
		}
		return btnInput;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("Input");
			lblNewLabel_1.setBounds(81, 10, 57, 15);
		}
		return lblNewLabel_1;
	}
}
